package cn.net.wanji.entity.deviceStatus;

import cn.net.wanji.entity.MyDeviceInfo;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author guodejun
 * @createTime 2022/11/18 16:39
 * @description
 */
@Data
public class DeviceStatus {

    String gantryId;
    String createTime;

    List<ControllerHeartbeat> controllerHeartbeatList;
    List<CameraHeartbeat> cameraHeartbeatList;
    List<LaserHeartbeat> laserHeartbeatList;
    List<RsuHeartbeat> rsuHeartbeatList;


    public List<MyDeviceInfo> getMyDeviceInfoList() {
        // 获取站点 id
        String siteCode = gantryId;

        List<MyDeviceInfo> myDeviceInfos = new ArrayList<>();
        // 控制器状态
        if (controllerHeartbeatList != null) {
            List<MyDeviceInfo> controllerMyDeviceInfo = controllerHeartbeatList.stream().map(item -> item.getDevBaseInfo(siteCode, "0101")).
                    collect(Collectors.toList());
            myDeviceInfos.addAll(controllerMyDeviceInfo);
        }

        // 相机状态
        if (cameraHeartbeatList != null) {
            List<MyDeviceInfo> cameraMyDeviceInfo = cameraHeartbeatList.stream().map(item -> item.getDevBaseInfo(siteCode, "0102")).collect(Collectors.toList());
            myDeviceInfos.addAll(cameraMyDeviceInfo);
        }
        // 激光雷达状态
        if (laserHeartbeatList != null) {
            List<MyDeviceInfo> laserMyDeviceInfo = laserHeartbeatList.stream().map(item -> item.getDevBaseInfo(siteCode, "0103")).collect(Collectors.toList());
            myDeviceInfos.addAll(laserMyDeviceInfo);
        }
        // 路侧单元状态
        if (rsuHeartbeatList != null) {
            List<MyDeviceInfo> rsuMyDeviceInfo = rsuHeartbeatList.stream().map(item -> item.getDevBaseInfo(siteCode, "0104")).collect(Collectors.toList());
            myDeviceInfos.addAll(rsuMyDeviceInfo);
        }

        return myDeviceInfos;
    }
}
